package com.aiwei.tdjk.service;

import com.aiwei.tdjk.bean.Pager;
import com.aiwei.tdjk.dto.request.GetUserPagerRequest;
import com.aiwei.tdjk.entity.User;
import com.aiwei.tdjk.entity.UserOrganizationJob;
import com.aiwei.tdjk.enums.UserStatusEnum;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by yanfeng on 2016/12/15.
 */
public interface UserService {


    User get(long id);

    void save(User user);

    int update(User user);

    int delete(Long id);

    int delete(Long[] ids);

    /**
     * 获取分页列表
     * @param request
     * @return
     */
    Pager<User> find(GetUserPagerRequest request);


    User findByUsername(String name);


    User findByUsernameOrMobileOrEmailOrEmployeeId(String name);


    User findByUsername(String name,Long id);


    User findByMobilePhoneNumber(String mobilePhoneNumber,Long id);

    User findByEmail(String email,Long id);

    User findEmployeeId(String employeeId,Long id);

//    @Query("from UserOrganizationJob where user=?1 and organizationId=?2 and jobId=?3")
    UserOrganizationJob findUserOrganization(User user, Long organizationId, Long jobId);


//    @Query("select uoj from UserOrganizationJob uoj where not exists(select 1 from Job j where uoj.jobId=j.id) or not exists(select 1 from Organization o where uoj.organizationId=o.id)")
    Pager<UserOrganizationJob> findUserOrganizationJobOnNotExistsOrganizationOrJob();

//    @Query("delete from UserOrganizationJob uoj where not exists(select 1 from User u where uoj.user=u)")
    void deleteUserOrganizationJobOnNotExistsUser();


    /*
    TODO
    同步全部数据接口实现片段：

    同步全部数据步骤：

    删除Activiti的User、Group、Membership数据

        复制Role对象数据到Group

        复制用户数据以及Membership数据
    */


    void changePassword(Long[] ids, String newPassword);

    Set<Map<String, Object>> findIdAndNames(String terms);

    /**
     * 通过用户所在组织查询组织员工
     * @param userId
     * @return
     */
    List<User> findUserByOrganization(Long userId);

    /**
     * 修改会员的状态
     */
    void changeStatus(Long[] ids,UserStatusEnum newStatus,String reason);

    List<User> findUsersByIds(List<Long> userIds);
    /**
     * 判断用户是否在职
     */
    Boolean isOnJob(Long userId);


}
